package com.example.demo.service;

import com.example.demo.model.User;
import com.example.demo.model.Follow;
import com.example.demo.mapper.FollowMapper;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class FollowService {
    private final FollowMapper followMapper;

    public FollowService(FollowMapper followMapper) { this.followMapper = followMapper; }

    // 关注
    public void follow(Long followedId, Long followerId) {
        followMapper.insertFollow(followedId, followerId);
    }

    // 取消关注
    public void unfollow(Long followedId, Long followerId) {
        followMapper.deleteFollow(followedId, followerId);
    }

    // 查询是否已关注
    public Follow getFollow(Long followedId, Long followerId) {
        return followMapper.selectOneFollow(followedId, followerId);
    }

    // 查询某用户的粉丝列表
    public List<Follow> getFollowers(Long followedId) {
        return followMapper.selectFollowers(followedId);
    }

    // 查询某用户关注的人列表
    public List<Follow> getFollowings(Long followerId) {
        return followMapper.selectFollowings(followerId);
    }
}
